package com.example.administrator.daydayappmarket.personal.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.daydayappmarket.DownloadActivity;
import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.personal.activity.PersonalAboutUsActivity;
import com.example.administrator.daydayappmarket.personal.activity.PersonalDeleteActivity;
import com.example.administrator.daydayappmarket.personal.activity.PersonalSettingActivity;
import com.example.administrator.daydayappmarket.personal.activity.PersonalUpgradeActivity;
import com.example.administrator.daydayappmarket.personal.adapter.PersonalAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A simple {@link Fragment} subclass.
 */
public class PersonalFragment extends Fragment implements AdapterView.OnItemClickListener {


    @InjectView(R.id.fragment_personal_imageView)
    ImageView fragmentPersonalImageView;
    @InjectView(R.id.fragment_personal_textView)
    TextView fragmentPersonalTextView;
    @InjectView(R.id.fragment_personal_relative)
    RelativeLayout fragmentPersonalRelative;
    @InjectView(R.id.fragment_personal_listView)
    ListView fragmentPersonalListView;


    int [] icons={R.drawable.app_update,R.drawable.task_manager,R.drawable.app_uninstall,R.drawable.settings,R.drawable.version_update,R.drawable.about_us,R.drawable.exit_app};

    private List<String> name;
    private List<Integer> icon;

    private PersonalAdapter adapter;
    public PersonalFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        name=new ArrayList<>();
        icon=new ArrayList<>();
        name.add(getResources().getString(R.string.fragmetn_personal_shengji));
        name.add(getResources().getString(R.string.fragmetn_personal_gunli));
        name.add(getResources().getString(R.string.fragmetn_personal_xiezai));
        name.add(getResources().getString(R.string.fragmetn_personal_shezhi));
        name.add(getResources().getString(R.string.fragmetn_personal_versionShengji));
        name.add(getResources().getString(R.string.fragmetn_personal_about));
        name.add(getResources().getString(R.string.fragmetn_personal_exit));
        for (int i = 0; i < icons.length; i++) {
            icon.add(icons[i]);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_personal, container, false);
        ButterKnife.inject(this, view);

        adapter=new PersonalAdapter(getContext(),name,icon);
        fragmentPersonalListView.setAdapter(adapter);
        fragmentPersonalListView.setOnItemClickListener(this);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent=new Intent();
        switch (position) {
            case 0://应用升级

                intent.setClass(getContext(),PersonalUpgradeActivity.class);
                startActivity(intent);
                break;
            case 1://任务管理

                intent.setClass(getContext(), DownloadActivity.class);
                startActivity(intent);
                break;
            case 2://应用卸载
                intent.setClass(getContext(), PersonalDeleteActivity.class);
                startActivity(intent);
                break;
            case 3://应用设置

                intent.setClass(getContext(),PersonalSettingActivity.class);
                startActivity(intent);
                break;
            case 4://版本升级

                break;
            case 5://关于我们
                intent.setClass(getContext(),PersonalAboutUsActivity.class);
                startActivity(intent);
                break;
            case 6://退出应用市场

                break;
        }
    }
}
